/*
	
	@obj	: captcha
	@ticket : 103391 
	@author : cpollard
	@notes  : configure the fields below and easily attach
			: onkeyup="captcha.keyup()"" to init ajax captcha validation 
	@updated: 12/3/2012
 */
var captcha = {
	// \/ Config \////////////////////////////////////////
	form 	: 'frm_70',
	answer 	: 'code',
	key 	: 'code_key',
	btn		: 'savefrm',
	<cfoutput>
	cfc     : '#REQUEST.ENV.WEBROOTFOLDER#includes/cfcs/CaptchaValidationUtil.cfc',
	</cfoutput>
	icon	: 'isCaptchaValid',
	iconImg : '/includes/images/assets/[BOOL]_ico.gif',
	api  	: 'isMatchSerial',
	// /\ Config /\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	keyup	: function(){
		var yesno = (this.isMatch() == true); 
		// The Submit Button
		$('#'+this.form+' :input[name='+this.btn+']').attr({		
			disabled 	: (yesno) ? false : true	// Disabled the form until captch 
		}).css({
			opacity 	: (yesno) ? 1 : 0.5			// Make it look disabled.
		}); 

		$('#'+this.answer).css({
			borderColor :  yesno ? 'green' : 'red',
			color  		:  yesno ? 'green' : 'red'
		});

		// $('img#'+this.icon).attr({
		// 	src : this.iconImg.replace('[BOOL]',yesno)
		// }).show();
	},
	isMatch	: function(){
		var isMatch = -1;
		var answer 	= $('#'+this.form+' :input[name='+this.answer+']').val();		// Our Captcha Code Input box 
		var key 	= $('#'+this.form+' :input[name='+this.key+']').val();		 
		if(answer.length == 4){	// Don't go validating unless we have 4 chars.
			$.ajax({
				url		: this.cfc,
				data 	: {
					method	: this.api,
					answer	: answer,
					key 	: key
				},
				dataType: 'json',
	 			async : false,
				success: function(data){
				  	isMatch = data;
				}
			});
		} 
		return isMatch;
	}
}; 